<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>数据 - AdminLTE2定制版 | Log in</title>

    <meta
            content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
            name="viewport">

    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
    <script src="${pageContext.request.contextPath}/plugins/jquery-3.3.1.js"></script>
    <script src="${pageContext.request.contextPath}/validate/jquery.validator.min.js"></script>
    <script src="${pageContext.request.contextPath}/validate/local/zh-CN.js"></script>
    <link href="${pageContext.request.contextPath}/validate/jquery.validator.css" rel="stylesheet">

</head>

<body class="hold-transition login-page">

<%--<%--%>
<%--String username="";--%>
<%--String pwd="";--%>
<%--String ck="";--%>
<%--//获取cookie--%>
<%--Cookie[] cookies=request.getCookies();--%>
<%--if(cookies!=null){--%>
<%--//遍历cookies--%>
<%--for (int i=0;i<cookies.length;i++){--%>
<%--String key=cookies[i].getName();--%>
<%--if("username".equals(key)){--%>
<%--username=cookies[i].getValue();--%>
<%--ck="checked";--%>
<%--}else if("pwd".equals(key)){--%>
<%--pwd=cookies[i].getValue();--%>
<%--}--%>
<%--}--%>

<%--//获取的用户名和密码存放在request作用域下--%>
<%--request.setAttribute("username",username);--%>
<%--request.setAttribute("pwd",pwd);--%>
<%--request.setAttribute("ck",ck);--%>
<%--}--%>

<%--%>--%>


<div class="login-box">
    <div class="login-logo">
        <a href="all-admin-index.html"><b>ITCAST</b>后台管理系统</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">登录系统</p>

        <!--登录错误提示消息-->
        <div id="errorMsg" style="color: red" ></div>
        <form id="loginForm" action="#" method="post" >
            <div class="form-group has-feedback">
                <input type="text" name="username" id="username" class="form-control" value="${cookie['username'].value}"
                       placeholder="用户名"> <span
                    class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" name="password" id="password" class="form-control" value="${cookie['password'].value}"
                       placeholder="密码" > <span
                    class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="text" id="check" name="check" placeholder="请输入验证码" >
                <span><img src="${pageContext.request.contextPath}/checkCode/check" alt="" onclick="changeCheckCode(this)"></span>
                <script type="text/javascript">
                    //图片点击事件
                    function changeCheckCode(img) {
                        img.src="${pageContext.request.contextPath}/checkCode/check?"+new Date().getTime();
                    }
                </script>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label><input type="checkbox" value="1" name="ck" id="ck" >自动登录</label>
                        <label><input type="checkbox" value="1" name="rb" id="rb" >记住密码</label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button id="btn_sub" type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
                </div>
                <!-- /.col -->
            </div>
        </form>


        <a href="#">忘记密码</a><br>


    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.2.3 -->
<!-- Bootstrap 3.3.6 -->
<!-- iCheck -->
<script
        src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script
        src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script
        src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });

    //1.给登录按钮绑定单击事件
    // $("#btn_sub").click(function () {
    //     //2.发送ajax请求，提交表单数据
    //     $.ajax({
    //         url: "/travel/system/userInfo/login",
    //         data: $("#loginForm").serialize(),
    //         dataType:"json",
    //         success: function (data) {
    //             alert("aaaaa")
    //             if (data.flag) {
    //                 //登录成功
    //                 location.href = "index.html";
    //
    //             } else {
    //                 //登录失败
    //                 $("#errorMsg").html(data.errorMsg);
    //
    //             }
    //         },
    //         error:function () {
    //             alert("bbbbbb")
    //         }
    //     });
    // });

    $("#loginForm").submit(function () {
        let username = $("#username").val();
        let password = $("#password").val();
        let check = $("#check").val();
        let ck=0;
        let rb=0;
        if (document.getElementById("ck").checked){
            ck=1;
        }
        if (document.getElementById("rb").checked){
            rb=1;
        }
        $.ajax({
            url:"/travel/system/userInfo/login",
            data:"username="+username+"&password="+password+"&check="+check+"&ck="+ck+"&rb="+rb,
            dataType:"json",
            success:function(data){
                if (data.flag) {
                    //登录成功
                    location.href = "/travel/index.jsp";

                } else {
                    //登录失败
                    $("#errorMsg").html(data.errorMsg);
                }
            },
            error:function () {
                alert("验证码未刷新")
            }
        });
        $("#loginForm").re
        return false;
    })
</script>
</body>

</html>